﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;


namespace MvcExceptionManagementSample
{
    public class BaseController : Controller {
        protected override void OnException(ExceptionContext filterContext)
        {
            if (filterContext.HttpContext.IsCustomErrorEnabled)
            {
                //just sample logging
                log4net.ILog log = log4net.LogManager.GetLogger(GetType());
                log.Error(filterContext.Exception.Message, filterContext.Exception);

                filterContext.ExceptionHandled = true;
                ViewData["ErrorMessage"] = filterContext.Exception.Message;
                this.View("Error").ExecuteResult(this.ControllerContext);
            }
        }       
    }  
}
